﻿@implements IDisposable

<MudGrid>
    <MudItem md="4">
        <MudButton OnClick="Get" Variant="Variant.Filled" StartIcon="@Icons.Custom.Uncategorized.Radioactive" Color="Color.Error">Get All Keys</MudButton>
    </MudItem>
    <MudItem md="4">
        <MudButton OnClick="Length" Variant="Variant.Filled" StartIcon="@Icons.Custom.Uncategorized.Radioactive" Color="Color.Success">Get Number of Keys</MudButton>
    </MudItem>
    <MudItem md="12">
        @string.Join(", ", Result)
    </MudItem>
    <MudItem md="12">
        @length
    </MudItem>
</MudGrid>

@code {

    private List<string> Result = new();

    private int? length;

    private async Task Get()
    {
        try
        {
            Result = await LocalStorage.KeysAsync();
        }
        catch (Exception ex)
        {
            Snackbar.Add($"{DashboardResource.StringError} : {ex.ToString()}", Severity.Error);
        }
    }

    private async Task Length()
    {
        try
        {
            length = await LocalStorage.LengthAsync();
        }
        catch (Exception ex)
        {
            Snackbar.Add($"{DashboardResource.StringError} : {ex.ToString()}", Severity.Error);
        }
    }

    public async void Dispose() => await Dom.DisposeAsync();
}